var express = require('express');
var router = express.Router();
var _ = require('underscore');

router.get('/', function (req, res, next) {
    var echostr = req.query.echostr;
    var signature = req.query.signature;
    var timestamp = req.query.timestamp;
    var nonce = req.query.nonce;

    var tmpArr = [token, timestamp, nonce]
    tmpStr = tmpArr.sort().join("")

    shaStr = hex_sha1(tmpStr)


    console.log("echostr:"+echostr)
    console.log('token:'+token);
    console.log('timestamp:'+timestamp);
    console.log('nonce:'+nonce);
    console.log('tmpStr:'+tmpStr);
    console.log('shastr:'+shaStr);
    console.log('++++++++++++++++++++++++++');
    console.log('signature:'+signature);
    if(shaStr == signature){
        console.log("success echostr:"+echostr)
        res.send(echostr);
    }else{
        console.log("error:"+echostr)
        res.json("error");
    }
});


module.exports = router;